/**
 * 物料批次品质异常隔离
 */
Ext.define('YX.smat.HoldMaterial', {
	  extend : 'Ext.panel.Panel',
	  layout : {
		  type : 'hbox',
		  align : 'stretch'
	  },
	  gridHoldMat : null,
	  txtSearchMsn : null,
	  sfSearchMatCode : null,
	  frmSearch : null,
	  txtHoldNo : null,
	  cmbHoldCode : null,
	  txtHoldPwd : null,
	  txtMemo : null,
	  btnHold : null,
	  btnSearch : null,
	  frmHold : null,
	  require : ['UX.codeview.FieldX'],
	  initComponent : function() {
		  var storeHold = Ext.create('Ext.data.JsonStore', {
			    fields : ['msn', 'matCode', 'matVer', 'matDesc', 'whCode', 'holdNo',
			      'holdCode', 'holdUser', {
				      type : 'date',
				      name : 'holdTime',
				      dateFormat : 'YmdHis'
			      }, 'holdMemo'],
			    proxy : {
				    type : 'zbusrpc',
				    module : 'SmatViewMaterialSnToHoldService',
				    reader : {
					    root : 'msnList'
				    }
			    }
		    });
		  this.gridHoldMat = Ext.create('Ext.grid.Panel', {
			    title : T.label.holdMaterialLot,
			    flex : 1,
			    columns : [{
				      text : T.label.msn,
				      dataIndex : 'msn'
			      }, {
				      text : T.label.matCode,
				      dataIndex : 'matCode'
			      }, {
				      text : T.label.matVer,
				      dataIndex : 'matVer',
				      width : 65
			      }, {
				      text : T.label.matDesc,
				      dataIndex : 'matDesc',
				      width : 150
			      }, {
				      text : T.label.warehouseCode,
				      dataIndex : 'whCode',
				      width : 65
			      }, {
				      text : T.label.holdNo,
				      dataIndex : 'holdNo'
			      }, {
				      text : T.label.holdCode,
				      dataIndex : 'holdCode'
			      }, {
				      text : T.label.holdUser,
				      dataIndex : 'holdUser',
				      width : 60
			      }, {
				      xtype : 'datecolumn',
				      text : T.label.holdTime,
				      dataIndex : 'holdTime',
				      width : 120,
				      format : 'Y-m-d H:i:s'
			      }, {
				      text : T.label.memo,
				      dataIndex : 'holdMemo'
			      }],
			    store : storeHold,
			    bbar : {
				    xtype : 'pagingtoolbar',
				    store : storeHold,
				    displayInfo : true
			    }
		    });

		  this.txtSearchMsn = Ext.create('Ext.form.field.Text', {
			    fieldLabel : T.label.msn,
			    labelWidth : 60,
			    anchor : '99%'
		    });
		  this.sfSearchMatCode = Ext.widget('codeviewfieldx', {
			    fieldLabel : T.label.matCode,
			    labelWidth : 60,
			    anchor : '99%',
			    columns : [{
				      text : T.label.matCode,
				      dataIndex : 'matCode',
				      width : 100
			      }, {
				      text : T.label.ver,
				      dataIndex : 'matVer',
				      width : 50
			      }, {
				      text : T.label.matDesc,
				      dataIndex : 'matDesc',
				      width : 150
			      }],
			    store : {
				    store : 'json',
				    fields : ['matCode', 'matVer', 'matDesc'],
				    proxy : {
					    type : 'zbusrpc',
					    module : 'SbasViewBaseMaterialService',
					    reader : {
						    type : 'json',
						    root : 'matList'
					    }
				    }
			    }
		    });
		  this.frmSearch = Ext.create('Ext.form.Panel', {
			    title : T.label.search,
			    items : [this.txtSearchMsn, this.sfSearchMatCode]
		    });

		  this.txtHoldNo = Ext.create('Ext.form.field.Text', {
			    fieldLabel : T.label.holdNo,
			    name : 'holdNo',
			    labelWidth : 60,
			    anchor : '99%',
			    readOnly : true
		    });
		  this.cmbHoldCode = Ext.create('Ext.form.field.ComboBox', {
			    fieldLabel : T.label.holdCode,
			    labelWidth : 60,
			    name : 'holdCode',
			    editable : false,
			    allowBlank : false,
			    anchor : '99%',
			    valueField : 'key1',
			    displayField : 'data1',
			    store : Ext.create('Ext.data.JsonStore', {
				      fields : ['key1', 'data1'],
				      autoLoad : true,
				      proxy : {
					      type : 'zbusrpc',
					      module : 'BasViewCommonDataSetupDetailService',
					      extraParams : {
						      groupName : 'MSN_LOCK_CODE'
					      },
					      reader : {
						      root : 'cdsDtlList'
					      }
				      }
			      })
		    });
		  this.txtHoldPwd = Ext.create('Ext.form.field.Text', {
			    fieldLabel : T.label.password,
			    name : 'holdPwd',
			    labelWidth : 60,
			    anchor : '99%',
			    maxLength : 20
		    });
		  this.txtMemo = Ext.create('Ext.form.field.Text', {
			    fieldLabel : T.label.memo,
			    name : 'memo',
			    labelWidth : 60,
			    anchor : '99%',
			    maxLength : 100
		    });
		  this.btnSearch = Ext.create('Ext.button.Button', {
			    text : T.label.search,
			    iconCls : 'icon-search',
			    scope : this,
			    handler : this.onBtnSearchClicked
		    });
		  this.btnHold = Ext.create('Ext.button.Button', {
			    text : T.label.hold,
			    iconCls : 'icon-lock',
			    itemId : 'btnHold',
			    scope : this,
			    handler : this.onBtnHoldClicked
		    });
		  this.frmHold = Ext.create('Ext.form.Panel', {
			    flex : 1,
			    title : T.label.holdMaterialLot,
			    items : [this.txtHoldNo, this.cmbHoldCode, this.txtHoldPwd, this.txtMemo],
			    bbar : {
				    xtype : 'toolbar',
				    items : [this.btnSearch, this.btnHold]
			    }
		    });

		  this.items = [this.gridHoldMat, {
			    width : 250,
			    layout : {
				    type : 'vbox',
				    align : 'stretch'
			    },
			    items : [this.frmSearch, this.frmHold]
		    }];

		  this.callParent();
	  },
	  onBtnSearchClicked : function(btn) {
		  var proxy = this.gridHoldMat.getStore().getProxy();
		  proxy.setExtraParam('msn', this.txtSearchMsn.getValue());
		  proxy.setExtraParam('matCode', this.sfSearchMatCode.getValue());
		  this.gridHoldMat.getStore().loadPage(1);
	  },
	  onBtnHoldClicked : function(btn) {
		  if (!this.frmHold.getForm().isValid()) {
			  return;
		  }

		  var reqParm = this.gridHoldMat.getStore().getProxy().extraParams;
		  var me = this;
		  Ext.Msg.show({
			    title : T.label.save,
			    msg : T.msg.are_you_sure_to_save_data,
			    icon : Ext.Msg.QUESTION,
			    buttons : Ext.Msg.YESNO,
			    fn : function(btnId) {
				    if (btnId == 'yes') {
					    btn.disable();

					    YX.ZbusRpc.request({
						      module : 'SmatHoldMaterialSnService',
						      params : {
							      msn : reqParm.msn,
							      matCode : reqParm.matCode
						      },
						      form : me.frmHold.getId(),
						      showSuccess : true,
						      callback : function() {
							      btn.enable();
						      },
						      success : function(rsp) {
							      me.gridHoldMat.getStore().loadPage(1);
							      me.txtHoldNo.setValue(rsp.holdNo);
						      }
					      });
				    }
			    }
		    });
	  }
  });